<%inherit file="base.html"/>

<%def name="head()">
<script src="/static/js/bootstrap-datepicker.js"></script>
<link rel="stylesheet" href="/static/js/datepicker.css"> 
   <script>
    $(document).ready(function(){
        $("#query_begin_time").datepicker();
        $("#query_end_time").datepicker();
    });
    function do_submit(){
        $("#query_form").attr("action", "/orders");
        $("#query_form").submit();
    }
    function do_export(){
        $("#query_form").attr("action", "/orders/export");
        $("#query_form").submit();
        setTimeout(function(){$("#query_form").attr("action", "/orders");}, 0);
    }
   </script>
</%def>

<%def name="body()">
<div class="panel panel-default">
    <div class="panel-heading"><span class="glyphicon glyphicon-th"></span> 用户订购查询</div>
    <div class="panel-body">
        <form id="query_form" class="form-horizontal form-well" role="form" action="/orders" method="post">
            <div class="form-group">
                <label for="node_id" class="col-md-2 control-label">区域</label>
                <div class="col-md-3">
                    <select id="node_id" name="node_id" class="form-control" >
                    <option value=""></option>
                        % for node in node_list:
                          <option value="${node.id}"  ${str(node.id)==node_id and "selected" or ""}>${node.node_desc}</option>
                        % endfor
                    </select>
                </div>  
                <label for="account_number" class="col-md-2 control-label">用户账号</label>
                <div class="col-md-3">
                    <input type="text" id="account_number" name="account_number" value="${account_number or ''}" class="form-control">
                </div>
            </div>   
            <div class="form-group">
                <label for="product_id" class="col-md-2 control-label">资费</label>
                <div class="col-md-3">
                    <select id="product_id" name="product_id" class="form-control" >
                    <option value=""></option>
                        % for product in products:
                          <option value="${product.id}"  ${str(product.id)==product_id and "selected" or ""}>${product.product_name}</option>
                        % endfor
                    </select>
                </div>  
                <label for="pay_status" class="col-md-2 control-label">支付状态</label>
                <div class="col-md-3">
                    <select id="pay_status" name="pay_status" class="form-control" >
                    <option value=""></option>
                    <option value="0"  ${"0"==pay_status and "selected" or ""}>未支付</option>
                    <option value="1"  ${"1"==pay_status and "selected" or ""}>已支付</option>
                    <option value="2"  ${"2"==pay_status and "selected" or ""}>已取消</option>
                    </select>
                </div>  
            </div>              
            <div class="form-group">
                <label for="query_begin_time" class="col-md-2 control-label">开始时间</label>

                <div class="col-md-3">
                    <input type="text" id="query_begin_time" name="query_begin_time" value="${query_begin_time or ''}" class="form-control form_datetime"  >
                </div>
                 <label for="query_end_time" class="col-md-2 control-label">结束时间</label>
                <div class="col-md-3">
                    <input type="text" id="query_end_time" name="query_end_time" value="${query_end_time or ''}"  class="form-control form_datetime">
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-offset-5 col-md-7">
                    <button type="button" onclick="do_submit();" class="btn btn-primary">查询</button>
                    % if permit.match('/orders/export'):
                    <a href="javascript:do_export();" class="btn btn-md btn-default"><span class="glyphicon glyphicon-arrow-down"></span>导出数据</a>
                    % endif
                </div>
            </div>
        </form>

        <table class="table table-hover">
            <thead>
            <tr>
                <th>订单号</th>
                <th>姓名</th>
                <th>账号</th>
                <th>资费</th>
                <th>应缴</th>
                <th>实缴</th>
                <th>状态</th>
                <th>时间</th>
                <th width="25%">描述</th>
            </tr>   
        </thead>
        <tbody>         
            % for order,_,_realname,_product_name,_ in page_data.result:
            <tr>
                <td>${order.order_id}</td>
                <td>${_realname}</td>
                <td><a href="/member/detail?account_number=${order.account_number}">${order.account_number}</a></td>
                <td>${_product_name}</td>
                <td>${fen2yuan(order.order_fee)}</td>
                <td>${fen2yuan(order.actual_fee)}</td>
                <td>${{0:u"未支付",1:u"已支付",2:u"已取消"}[order.pay_status]}</td>
                <td>${order.create_time}</td>
                <td>${order.order_desc or ''}</td>
            </tr>
            % endfor
            </tbody>
        </table>  

        ${page_data.render(form_id="query_form")}
    </div>
</div>


</%def>
